package org.anupta.game.entity.entities;

public class Item extends Entity {
	private int id = 0;
	private ItemTemplate temp = null;
	private Position pos = Position.NO_EQUIPED;
	private int quantity = 1;

	public Item() {
	}

	@Override
	public int getGuid() {
		return id;
	}

	@Override
	public void setGuid(int id) {
		this.id = id;
	}

	@Override
	public String getName() {
		return getTemp().getName();
	}

	@Override
	public void setName(String name) {
		getTemp().setName(name);
	}

	public ItemTemplate getTemp() {
		return temp;
	}

	public void setTemp(ItemTemplate temp) {
		this.temp = temp;
	}
	
	public Position getPos() {
		return pos;
	}

	public void setPos(Position pos) {
		this.pos = pos;
	}
	
	public int getQuantity() {
		return quantity;
	}

	public void setQuantity(int qty) {
		this.quantity = qty;
	}
	
	public String getItemString(){
		StringBuilder item = new StringBuilder();
		item.append(Integer.toHexString(id)).append("~").append(Integer.toHexString(temp.getGuid())).append("~")
		.append(Integer.toHexString(quantity)).append((pos == Position.NO_EQUIPED ? "" : Integer.toHexString(((int)pos.getPos())))).append("~")
		.append(getStatString()).append(";");
		return item.toString();
	}
	
	public String getStatString(){
		//TODO: Finish
		StringBuilder stat = new StringBuilder();
		return stat.toString();
	}

	public static enum Position{
		NO_EQUIPED((byte)-1),
		AMULETTE((byte)0),
		ARME((byte)1),
		ANNEAU1((byte)2),
		CEINTURE((byte)3),
		ANNEAU2((byte)4),
		BOTTE((byte)5),
		COIFFE((byte)6),
		CAPE((byte)7),
		FAMILIER((byte)8),
		DOFUS1((byte)9),
		DOFUS2((byte)10),
		DOFUS3((byte)11),
		DOFUS4((byte)12),
		DOFUS5((byte)13),
		DOFUS6((byte)14),
		BOUCLIER((byte)15);
		
		private byte pos = -1;
		
		private Position(byte pos){
			setPos(pos);
		}

		public byte getPos() {
			return pos;
		}

		public void setPos(byte pos) {
			this.pos = pos;
		}
		
		public static Position get(byte pos){
			switch(pos){
			case 0:
				return AMULETTE;
			case 1:
				return ARME;
			case 2:
				return ANNEAU1;
			case 3:
				return CEINTURE;
			case 4:
				return ANNEAU2;
			case 5:
				return BOTTE;
			case 6:
				return COIFFE;
			case 7:
				return CAPE;
			case 8:
				return FAMILIER;
			case 9:
				return DOFUS1;
			case 10:
				return DOFUS2;
			case 11:
				return DOFUS3;
			case 12:
				return DOFUS4;
			case 13:
				return DOFUS5;
			case 14:
				return DOFUS6;
			case 15:
				return BOUCLIER;
			}
			return NO_EQUIPED;
		}
	}
}
